<?php
include_once("../config.php");
include_once("../web_config.php");
require_once("XmlDeleteApp.php");


//include_once(APPLICATION_ROOT."/web_config.php");
//include_once(APPLICATION_ROOT."/config.php");
include_once("../oracleaccess/classes/DbConnect.php" );
$connessione = new DbConnect();//connessione viste locale

$array_cig=explode(",",$_REQUEST["cig"]);

$array_id_cig=array();
foreach($array_cig as $key=>$value){
  $array_id_cig[]=array("ID"=>$value);
}


$array_schede=array();
for($x=0; $x<count($array_id_cig); $x++)
{
  $id_cig=$array_id_cig[$x]['ID'];
  
  
  $sel_scheda="select cig,scheda,NUM_PROGR,NUM_PROGR_SCHEDA from  GARE_SCHEDE_CANCELLATE where id=".$id_cig." ";
  $query_scheda = $connessione->doquery_oracle($sel_scheda, 'select');
  //echo("sel_scheda = ".$sel_scheda);
  $array_schede[$x]["CIG"]=$query_scheda[1][1]; //cig
  $array_schede[$x]["SCHEDA"]=$query_scheda[1][2]; //scheda
  $array_schede[$x]["NUM_PROGR"]=$query_scheda[1][3]; //NUM_PROGR
  $array_schede[$x]["NUM_PROGR_SCHEDA"]=$query_scheda[1][4]; //NUM_PROGR_SCHEDA
  if($query_scheda[1][2]!="GARE" AND $query_scheda[1][2]!="GARE_SS")
  {
   	//ECHO("query_scheda[$x][\"SCHEDA\"] = ".$query_scheda[$x]["SCHEDA"]);
    $sel_cui="SELECT CUI FROM AGGIUDICAZIONE WHERE CIG='".$query_scheda[1][1]."' AND NUM_PROGR=".$query_scheda[1][3]."
             UNION SELECT CUI FROM AGGIUDICAZIONE_SS WHERE CIG='".$query_scheda[1][1]."' AND NUM_PROGR=".$query_scheda[1][3];
    $query_sel_cui ="";
    $query_sel_cui = $connessione->doquery_oracle($sel_cui, 'select');
    $cui=$query_sel_cui[1][1];
    $array_schede[$x]["CUI"]=$cui; //cui
		   
    $sel_id_locale="select id from ".$query_scheda[1][2]." WHERE CIG='".$query_scheda[1][1]."' ";
    if(!empty($query_scheda[1][3]))
    {
	  $sel_id_locale .="and NUM_PROGR ='".$query_scheda[1][3]."' ";  
    }
    if(!empty($query_scheda[1][4]))
    {
	  $sel_id_locale .="and NUM_PROGR_SCHEDA ='".$query_scheda[1][4]."' ";  
    }
    //echo($sel_id_locale);
    $query_sel_id_locale = $connessione->doquery_oracle($sel_id_locale, 'select');
    $id_locale=$query_sel_id_locale[1][1];
    
    $array_schede[$x]["ID_SCHEDA_LOCALE"]=$id_locale; //id_locale
  }
  
}

//Restituisce true o false in relazione alla validazione dell'xml
XmlDeleteApp::getInstance()->Generate($array_schede); //QUI NON GESTIAMO PIU IL CHECK COME FEEDBACK DI SCRITTURA



?>